package com.mars.rabbitmq.delayPlugins;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author King
 * @create 2020/8/19 14:21
 */
@Slf4j
@Component
public class DelayPluginsConsumer {

    @RabbitListener(queues = DelayPluginsRabbitMqConfig.DELAY_QUEUE)
    public void onMessage(Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        String tmp = message.getMessageProperties().getCorrelationId();
        try {
            //TODO 处理业务
            log.info("receive订单信息:" + tmp + new String(message.getBody()));
            log.info("先查询是否已经支付");
            log.info("超时支付取消订单");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        channel.basicAck(deliveryTag, true);
    }


}
